#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minCost(vector<vector<int>>& costs) {
        int n = costs.size();
        vector<int> dred(n + 1), dblue(n + 1), dgreen(n + 1);
        for (int i = 1; i <= n; i++)
        {
            dred[i] = min(dblue[i - 1], dgreen[i - 1]) + costs[i - 1][0];
            dblue[i] = min(dred[i - 1], dgreen[i - 1]) + costs[i - 1][1];
            dgreen[i] = min(dred[i - 1], dblue[i - 1]) + costs[i - 1][2];
        }
        return min(min(dred[n], dblue[n]), dgreen[n]);
    }
};